package com.ruoyi.wechat.service.impl;

import com.ruoyi.common.utils.ConvertUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.domain.Activity;
import com.ruoyi.wechat.domain.WxActivity;
import com.ruoyi.wechat.mapper.ActivityMapper;
import com.ruoyi.wechat.service.IWxActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>ClassName : WxActivityServiceImpl</p>
 * <p>Description : </p>
 *
 * @author 孙伟光
 * @version 1.0
 * @date 2024/7/31 15:51
 */
@Service
public class WxActivityServiceImpl implements IWxActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    /**
     * 根据营地Id查询该营地的所有活动
     * @param campId 营地Id
     * @return 该营地的活动列表
     */
    @Override
    public List<WxActivity> getInfoByCampId(String campId) {
        //封装条件
        Activity activity = new Activity();
        activity.setCampId(campId);
        activity.setApprove("1");
        //根据营地Id获取营地下的活动列表
        List<Activity> list  = activityMapper.selectActivityList(activity);
        //数据类型转换
        if (list != null && list.size() > 0) {
            return ConvertUtils.sourceToTarget(list, WxActivity.class);
        }
        return null;
    }

    /**
     * 根据活动Id获取详细信息
     * @param activityId 活动Id
     * @return 活动对象
     */
    @Override
    public WxActivity getInfo(String activityId) {
        //根据活动id查询对象
        Activity activity = activityMapper.selectActivityByActivityId(activityId);
        return ConvertUtils.sourceToTarget(activity, WxActivity.class);
    }

    /**
     * 新增活动
     *
     * @param wxActivity 活动
     * @return 结果
     */
    @Override
    public int insertWxActivity(WxActivity wxActivity) {
        //设置条件
        wxActivity.setActivityId(IdUtils.randomUUID());
        wxActivity.setApprove("0");
        //数据类型转换
        Activity activity = ConvertUtils.sourceToTarget(wxActivity, Activity.class);
        //新增活动
        return activityMapper.insertActivity(activity);
    }

    /**
     * 修改活动
     *
     * @param wxActivity 活动
     * @return 结果
     */
    @Override
    public int updateWxActivity(WxActivity wxActivity) {
        //设置条件
        wxActivity.setApprove("0");
        //数据类型转换
        Activity activity = ConvertUtils.sourceToTarget(wxActivity, Activity.class);
        //修改活动
        return activityMapper.updateActivity(activity);
    }

    /**
     * 删除活动信息
     *
     * @param activityId 活动主键
     * @return 结果
     */
    @Override
    public int deleteWxActivityByActivityId(String activityId) {
        return activityMapper.deleteActivityByActivityId(activityId);
    }
}
